package com.prs.crm.action.oa;

import java.io.File;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.domain.hr.Dept;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.PictureNewsCollectType;
import com.prs.crm.domain.oa.Vehicle;
import com.prs.crm.domain.oa.WorkSummary;
import com.prs.crm.service.hr.DeptService;
import com.prs.crm.service.oa.VehicleService;

public class VehicleAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private Vehicle vehicle;
	private VehicleService vehicleService;
	private List<Dept> depts;
	private DeptService deptService;
	private File upload;
	private String uplodS;
	private String uploadFileName;
	private Integer[] ids;
	
	@Action("editVehicle")
	public String editVehicle() {
		this.depts=this.deptService.getAllDept();
		return SUCCESS;
	}
	@Action("viewVehicle")
	public String viewVehicle() {		
		return SUCCESS;
	}
	@Action("listVehicle")
	public String listVehicle() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Vehicle.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.vehicleService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action(value = "saveVehicle", results = {
			@Result(name = "success", type = "redirect", location = "listVehicle"),
			@Result(name = "error", type = "chain", location = "editVehicle") })
	public String saveVehicle(){
	    if(uplodS!=null){
	    	upload=new File(uplodS);
	    	this.getVehicleService().saveVehicles(vehicle, upload, uploadFileName);
	    }
		this.vehicle.setState("正常");
		this.vehicleService.save(vehicle);
		return SUCCESS;
	}
	@Action(value = "removeVehicle", results = {
			@Result(name = "success", type = "redirect", location = "listVehicle"),
			@Result(name = "error", type = "chain", location = "listVehicle") })
	public String removeVehicle(){
	 	if(ids==null){
	 		this.addActionError("请选择操作行！");
	 		return ERROR;
	 	}
	 	this.getVehicleService().batchRemove(ids);
	 	return SUCCESS;
	}	
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Vehicle getVehicle() {
		return vehicle;
	}
	public void setVehicle(Vehicle vehicle) {
		this.vehicle = vehicle;
	}
	public VehicleService getVehicleService() {
		return vehicleService;
	}
	public void setVehicleService(VehicleService vehicleService) {
		this.vehicleService = vehicleService;
	}
	public List<Dept> getDepts() {
		return depts;
	}
	public void setDepts(List<Dept> depts) {
		this.depts = depts;
	}
	public DeptService getDeptService() {
		return deptService;
	}
	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public String getUplodS() {
		return uplodS;
	}
	public void setUplodS(String uplodS) {
		this.uplodS = uplodS;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	
}
